home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / tcp.h < prev    next >
C/C++ Source or Header  |  1992-05-28  |  11KB  |  314 lines

  1. /* @(#) $Header: tcp.h,v 1.8 92/05/28 13:50:34 deyke Exp $ */
  2.  
  3. #ifndef _TCP_H
  4. #define _TCP_H
  5.  
  6. /* TCP implementation. Follows RFC 793 as closely as possible */
  7. #ifndef _GLOBAL_H
  8. #include "global.h"
  9. #endif
  10.  
  11. #ifndef _MBUF_H
  12. #include "mbuf.h"
  13. #endif
  14.  
  15. #ifndef _IFACE_H
  16. #include "iface.h"
  17. #endif
  18.  
  19. #ifndef _INTERNET_H
  20. #include "internet.h"
  21. #endif
  22.  
  23. #ifndef _IP_H
  24. #include "ip.h"
  25. #endif
  26.  
  27. #ifndef _NETUSER_H
  28. #include "netuser.h"
  29. #endif
  30.  
  31. #ifndef _TIMER_H
  32. #include "timer.h"
  33. #endif
  34.  
  35. #define DEF_MSS 512     /* Default maximum segment size */
  36. #define DEF_WND 2048    /* Default receiver window */
  37. #define RTTCACHE 16     /* # of TCP round-trip-time cache entries */
  38. #define DEF_RTT 5000    /* Initial guess at round trip time (5 sec) */
  39. #define MSL2    30      /* Guess at two maximum-segment lifetimes */
  40. #define MIN_RTO 500L    /* Minimum timeout, milliseconds */
  41. #define TCP_HDR_PAD     70      /* mbuf size to preallocate for headers */
  42.  
  43. #define geniss()        ((int32)msclock() << 12) /* Increment clock at 4 MB/sec */
  44.  
  45. /* Number of consecutive duplicate acks to trigger fast recovery */
  46. #define TCPDUPACKS      3
  47.  
  48. /* Round trip timing parameters */
  49. #define AGAIN   8       /* Average RTT gain = 1/8 */
  50. #define LAGAIN  3       /* Log2(AGAIN) */
  51. #define DGAIN   4       /* Mean deviation gain = 1/4 */
  52. #define LDGAIN  2       /* log2(DGAIN) */
  53.  
  54. /* TCP segment header -- internal representation
  55.  * Note that this structure is NOT the actual header as it appears on the
  56.  * network (in particular, the offset field is missing).
  57.  * All that knowledge is in the functions ntohtcp() and htontcp() in tcpsubr.c
  58.  */
  59. #define TCPLEN          20      /* Minimum Header length, bytes */
  60. #define TCP_MAXOPT      40      /* Largest option field, bytes */
  61. struct tcp {
  62.     int16 source;   /* Source port */
  63.     int16 dest;     /* Destination port */
  64.     int32 seq;      /* Sequence number */
  65.     int32 ack;      /* Acknowledgment number */
  66.     int16 wnd;                      /* Receiver flow control window */
  67.     int16 checksum;                 /* Checksum */
  68.     int16 up;                       /* Urgent pointer */
  69.     int16 mss;                      /* Optional max seg size */
  70.     struct {
  71.         char congest;   /* Echoed IP congestion experienced bit */
  72.         char urg;
  73.         char ack;
  74.         char psh;
  75.         char rst;
  76.         char syn;
  77.         char fin;
  78.     } flags;
  79.     char optlen;                    /* Length of options field, bytes */
  80.     char options[TCP_MAXOPT];       /* Options field */
  81. };
  82. /* TCP options */
  83. #define EOL_KIND        0
  84. #define NOOP_KIND       1
  85. #define MSS_KIND        2
  86. #define MSS_LENGTH      4
  87.  
  88. /* Resequencing queue entry */
  89. struct reseq {
  90.     struct reseq *next;     /* Linked-list pointer */
  91.     struct tcp seg;         /* TCP header */
  92.     struct mbuf *bp;        /* data */
  93.     int16 length;           /* data length */
  94.     char tos;               /* Type of service */
  95. };
  96. #define NULLRESEQ       (struct reseq *)0
  97.  
  98. /* TCP connection control block */
  99. struct tcb {
  100.     struct tcb *next;       /* Linked list pointer */
  101.  
  102.     struct connection conn;
  103.  
  104.     char state;     /* Connection state */
  105.  
  106. /* These numbers match those defined in the MIB for TCP connection state */
  107. #define TCP_CLOSED              1
  108. #define TCP_LISTEN              2
  109. #define TCP_SYN_SENT            3
  110. #define TCP_SYN_RECEIVED        4
  111. #define TCP_ESTABLISHED         5
  112. #define TCP_FINWAIT1            6
  113. #define TCP_FINWAIT2            7
  114. #define TCP_CLOSE_WAIT          8
  115. #define TCP_LAST_ACK            9
  116. #define TCP_CLOSING             10
  117. #define TCP_TIME_WAIT           11
  118.  
  119.     char reason;            /* Reason for closing */
  120. #define NORMAL          0       /* Normal close */
  121. #define RESET           1       /* Reset by other end */
  122. #define TIMEOUT         2       /* Excessive retransmissions */
  123. #define NETWORK         3       /* Network problem (ICMP message) */
  124.  
  125. /* If reason == NETWORK, the ICMP type and code values are stored here */
  126.     char type;
  127.     char code;
  128.  
  129.     /* Send sequence variables */
  130.     struct {
  131.         int32 una;      /* First unacknowledged sequence number */
  132.         int32 nxt;      /* Next sequence num to be sent for the first time */
  133.         int32 ptr;      /* Working transmission pointer */
  134.         int32 wl1;      /* Sequence number used for last window update */
  135.         int32 wl2;      /* Ack number used for last window update */
  136.         int16 wnd;      /* Other end's offered receive window */
  137.         int16 up;       /* Send urgent pointer */
  138.     } snd;
  139.     int32 iss;              /* Initial send sequence number */
  140.     int32 resent;           /* Count of bytes retransmitted */
  141.     int16 cwind;            /* Congestion window */
  142.     int16 ssthresh;         /* Slow-start threshold */
  143.     int dupacks;            /* Count of duplicate (do-nothing) ACKs */
  144.  
  145.     /* Receive sequence variables */
  146.     struct {
  147.         int32 nxt;      /* Incoming sequence number expected next */
  148.         int16 wnd;      /* Our offered receive window */
  149.         int16 up;       /* Receive urgent pointer */
  150.     } rcv;
  151.     int32 irs;              /* Initial receive sequence number */
  152.     int32 rerecv;           /* Count of duplicate bytes received */
  153.     int16 mss;              /* Maximum segment size */
  154.  
  155.     int16 window;           /* Receiver window and send queue limit */
  156.     int16 limit;            /* Send queue limit */
  157.  
  158.     void (*r_upcall) __ARGS((struct tcb *tcb,int cnt));
  159.         /* Call when "significant" amount of data arrives */
  160.     void (*t_upcall) __ARGS((struct tcb *tcb,int cnt));
  161.         /* Call when ok to send more data */
  162.     void (*s_upcall) __ARGS((struct tcb *tcb,int old,int new));
  163.         /* Call when connection state changes */
  164.     struct {                /* Control flags */
  165.         char force;     /* We owe the other end an ACK or window update */
  166.         char clone;     /* Server-type TCB, cloned on incoming SYN */
  167.         char retran;    /* A retransmission has occurred */
  168.         char active;    /* TCB created with an active open */
  169.         char synack;    /* Our SYN has been acked */
  170.         char rtt_run;   /* We're timing a segment */
  171.         char congest;   /* Copy of last IP congest bit received */
  172.     } flags;
  173.     char tos;               /* Type of service (for IP) */
  174.     int backoff;            /* Backoff interval */
  175.  
  176.     struct mbuf *rcvq;      /* Receive queue */
  177.     struct mbuf *sndq;      /* Send queue */
  178.     int16 rcvcnt;           /* Count of items on rcvq */
  179.     int16 sndcnt;           /* Number of unacknowledged sequence numbers on
  180.                  * sndq. NB: includes SYN and FIN, which don't
  181.                  * actually appear on sndq!
  182.                  */
  183.  
  184.     struct reseq *reseq;    /* Out-of-order segment queue */
  185.     struct timer timer;     /* Retransmission timer */
  186.     int32 rtt_time;         /* Stored clock values for RTT */
  187.     int32 rttseq;           /* Sequence number being timed */
  188.     int32 srtt;             /* Smoothed round trip time, milliseconds */
  189.     int32 mdev;             /* Mean deviation, milliseconds */
  190.     int32 lastactive;       /* Clock time when xmtr last active */
  191.  
  192.     int user;               /* User parameter (e.g., for mapping to an
  193.                  * application control block
  194.                  */
  195. };
  196. #define NULLTCB (struct tcb *)0
  197. /* TCP round-trip time cache */
  198. struct tcp_rtt {
  199.     int32 addr;             /* Destination IP address */
  200.     int32 srtt;             /* Most recent SRTT */
  201.     int32 mdev;             /* Most recent mean deviation */
  202. };
  203. #define NULLRTT (struct tcp_rtt *)0
  204. extern struct tcp_rtt Tcp_rtt[];
  205.  
  206. /* TCP statistics counters */
  207. struct tcp_stat {
  208.     int16 runt;             /* Smaller than minimum size */
  209.     int16 checksum;         /* TCP header checksum errors */
  210.     int16 conout;           /* Outgoing connection attempts */
  211.     int16 conin;            /* Incoming connection attempts */
  212.     int16 resets;           /* Resets generated */
  213.     int16 bdcsts;           /* Bogus broadcast packets */
  214. };
  215. extern struct mib_entry Tcp_mib[];
  216. #define tcpRtoAlgorithm Tcp_mib[1].value.integer
  217. #define tcpRtoMin       Tcp_mib[2].value.integer
  218. #define tcpRtoMax       Tcp_mib[3].value.integer
  219. #define tcpMaxConn      Tcp_mib[4].value.integer
  220. #define tcpActiveOpens  Tcp_mib[5].value.integer
  221. #define tcpPassiveOpens Tcp_mib[6].value.integer
  222. #define tcpAttemptFails Tcp_mib[7].value.integer
  223. #define tcpEstabResets  Tcp_mib[8].value.integer
  224. #define tcpCurrEstab    Tcp_mib[9].value.integer
  225. #define tcpInSegs       Tcp_mib[10].value.integer
  226. #define tcpOutSegs      Tcp_mib[11].value.integer
  227. #define tcpRetransSegs  Tcp_mib[12].value.integer
  228. #define tcpInErrs       Tcp_mib[14].value.integer
  229. #define tcpOutRsts      Tcp_mib[15].value.integer
  230. #define NUMTCPMIB       15
  231.  
  232. extern struct tcb *Tcbs;
  233. extern char *Tcpstates[];
  234. extern char *Tcpreasons[];
  235.  
  236. /* In tcpcmd.c: */
  237. extern int32 Tcp_irtt;
  238. extern int16 Tcp_limit;
  239. extern int16 Tcp_mss;
  240. extern int Tcp_syndata;
  241. extern int Tcp_trace;
  242. extern int16 Tcp_window;
  243.  
  244. void st_tcp __ARGS((struct tcb *tcb));
  245.  
  246. /* In tcphdr.c: */
  247. struct mbuf *htontcp __ARGS((struct tcp *tcph,struct mbuf *data,
  248.     struct pseudo_header *ph));
  249. int ntohtcp __ARGS((struct tcp *tcph,struct mbuf **bpp));
  250.  
  251. /* In tcpin.c: */
  252. void reset __ARGS((struct ip *ip,struct tcp *seg));
  253. void send_syn __ARGS((struct tcb *tcb));
  254. void tcp_input __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,
  255.     int rxbroadcast));
  256. void tcp_icmp __ARGS((int32 icsource,int32 source,int32 dest,
  257.     int type,int code,struct mbuf **bpp));
  258.  
  259. /* In tcpsubr.c: */
  260. void close_self __ARGS((struct tcb *tcb,int reason));
  261. struct tcb *create_tcb __ARGS((struct connection *conn));
  262. struct tcb *lookup_tcb __ARGS((struct connection *conn));
  263. void rtt_add __ARGS((int32 addr,int32 rtt));
  264. struct tcp_rtt *rtt_get __ARGS((int32 addr));
  265. int seq_ge __ARGS((int32 x,int32 y));
  266. int seq_gt __ARGS((int32 x,int32 y));
  267. int seq_le __ARGS((int32 x,int32 y));
  268. int seq_lt __ARGS((int32 x,int32 y));
  269. int seq_within __ARGS((int32 x,int32 low,int32 high));
  270. void setstate __ARGS((struct tcb *tcb,int newstate));
  271. void tcp_garbage __ARGS((int red));
  272.  
  273. /* In tcpout.c: */
  274. void tcp_output __ARGS((struct tcb *tcb));
  275.  
  276. /* In tcptimer.c: */
  277. int32 backoff __ARGS((int n));
  278. void tcp_timeout __ARGS((void *p));
  279.  
  280. /* In tcpuser.c: */
  281. int close_tcp __ARGS((struct tcb *tcb));
  282. int del_tcp __ARGS((struct tcb *tcb));
  283. int kick __ARGS((int32 addr));
  284. int kick_tcp __ARGS((struct tcb *tcb));
  285. struct tcb *open_tcp __ARGS((struct socket *lsocket,struct socket *fsocket,
  286.     int mode,int window,
  287.     void (*r_upcall) __ARGS((struct tcb *tcb,int cnt)),
  288.     void (*t_upcall) __ARGS((struct tcb *tcb,int cnt)),
  289.     void (*s_upcall) __ARGS((struct tcb *tcb,int old,int new)),
  290.     int tos,int user));
  291. int recv_tcp __ARGS((struct tcb *tcb,struct mbuf **bpp,int cnt));
  292. void reset_all __ARGS((void));
  293. void reset_tcp __ARGS((struct tcb *tcb));
  294. int send_tcp __ARGS((struct tcb *tcb,struct mbuf *bp));
  295. int space_tcp __ARGS((struct tcb *tcb));
  296. char *tcp_port __ARGS((int n));
  297. int tcpval __ARGS((struct tcb *tcb));
  298.  
  299. /* In tcpsocket.c: */
  300. int so_tcp __ARGS((struct usock *up,int protocol));
  301. int so_tcp_listen __ARGS((struct usock *up,int backlog));
  302. int so_tcp_conn __ARGS((struct usock *up));
  303. int so_tcp_recv __ARGS((struct usock *up,struct mbuf **bpp,char *from,
  304.     int *fromlen));
  305. int so_tcp_send __ARGS((struct usock *up,struct mbuf *bp,char *to));
  306. int so_tcp_qlen __ARGS((struct usock *up,int rtx));
  307. int so_tcp_kick __ARGS((struct usock *up));
  308. int so_tcp_shut __ARGS((struct usock *up,int how));
  309. int so_tcp_close __ARGS((struct usock *up));
  310. char *tcpstate __ARGS((struct usock *up));
  311. int so_tcp_stat __ARGS((struct usock *up));
  312.  
  313. #endif  /* _TCP_H */
  314.